/**
 * 
 */
package com.nari.beshs.validform;

import org.apache.struts2.json.JSONUtil;
import org.apache.struts2.json.annotations.JSON;

import com.nari.baseinfo.service.IBuildingService;
import com.nari.baseinfo.service.IBuildingUnitService;
import com.nari.baseinfo.service.IConcentratorService;
import com.nari.baseinfo.service.IHeatMeterService;
import com.nari.baseinfo.service.IProjectService;
import com.nari.baseinfo.service.IQueryerService;
import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.heatshare.service.IAssignMeterService;
import com.nari.heatshare.service.IHeatMeterTypeParamDictService;
import com.nari.platform.components.validform.CallbackMsg;
import com.nari.sink.service.ISinkBiz;
import com.opensymphony.xwork2.Action;

/**
 * 基于Validform_v5.3.2的表单异步验证
 * @author Xiaopeng
 * @date 2014-7-21
 */
public class FormAsyncValidateAction extends JSONActionSupport {
	private static final long serialVersionUID = 7311744860385455870L;
	private IBuildingService iBuildingService;
	private IBuildingUnitService iBuildingUnitService;
	private IConcentratorService iConcentratorService;
	private IHeatMeterService iHeatMeterService;
	private IProjectService iProjectService;
	private IQueryerService iQueryerService;
	private IAssignMeterService iAssignMeterService;
	private IHeatMeterTypeParamDictService iHeatMeterTypeParamDictService;
	private ISinkBiz iSinkBiz;
	//文本框的name属性
	private String name;
	//文本框的值
	private String param;
	//实体的唯一标识
	private String entityUuid;
	//校验关联信息
	private String buildingUID;
	
	/**
	 * 验证楼栋编号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-22
	 */
	public String validBuildingIDUnique() throws Exception {
		//统计相同楼栋编号的个数
		int counter = iBuildingService.countByBuildingID(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Building No. validate！");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Building No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证单元名称的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-22
	 */
	public String validUnitNameUnique() throws Exception {
		//统计相同楼栋编号的个数
		int counter = iBuildingUnitService.countByUnitName(param, buildingUID, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Unit Name validate!！");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Unit Name exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证集中器号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-23
	 */
	public String validConcentratorNoUnique() throws Exception {
		//统计相同集中器号的个数
		int counter = iConcentratorService.countByConcentratorNo(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Concentrator No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Concentrator No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证热量表表号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-24
	 */
	public String validMeterNoUnique() throws Exception {
		//统计相同热量表表号的个数
		int counter = iHeatMeterService.queryMeterNoUniqueCount(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This HeatMeter No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This HeatMeter No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证项目编号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-24
	 */
	public String validProjectIDUnique() throws Exception {
		//统计相同项目编号的个数
		int counter = iProjectService.countRepeatProjectIDNum(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Project No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Project No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证查询器编号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-24
	 */
	public String validQueryerNoUnique() throws Exception {
		//统计相同查询器编号的个数
		int counter = iQueryerService.countByQueryerNo(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Query Device No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Query Device exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证分配表表号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-28
	 */
	public String validSeriousNumUnique() throws Exception {
		//统计相同分配表表号的个数
		int counter = iAssignMeterService.countBySeriousNum(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Allocator No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Allocator No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证热量表型号编号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-28
	 */
	public String validTypeCodeUnique() throws Exception {
		//统计相同热量表型号编号的个数
		int counter = iHeatMeterTypeParamDictService.countTypeParamByTypeCode(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This HeatMeter Type validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This HeatMeter Type exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * 验证散热器编号的唯一性
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-7-28
	 */
	public String validSinkNoUnique() throws Exception {
		//统计相同散热器编号的个数
		int counter = iSinkBiz.countBySinkNo(param, entityUuid);
		//构造响应信息
		CallbackMsg cmsg = CallbackMsg.getInstance(true, "This Radiator No. validate!");
		if(counter > 0) {
			cmsg = CallbackMsg.getInstance(false, "This Radiator No. exists,Please enter another!");
		}
		this.writeJsonStrToResponse(JSONUtil.serialize(cmsg));
		return Action.SUCCESS;
	}
	
	/**
	 * @return the iBuildingService
	 */
	@JSON(serialize=false)
	public IBuildingService getiBuildingService() {
		return iBuildingService;
	}

	/**
	 * @param iBuildingService the iBuildingService to set
	 */
	public void setiBuildingService(IBuildingService iBuildingService) {
		this.iBuildingService = iBuildingService;
	}

	/**
	 * @return the iBuildingUnitService
	 */
	@JSON(serialize=false)
	public IBuildingUnitService getiBuildingUnitService() {
		return iBuildingUnitService;
	}

	/**
	 * @param iBuildingUnitService the iBuildingUnitService to set
	 */
	public void setiBuildingUnitService(IBuildingUnitService iBuildingUnitService) {
		this.iBuildingUnitService = iBuildingUnitService;
	}

	/**
	 * @return the iConcentratorService
	 */
	@JSON(serialize=false)
	public IConcentratorService getiConcentratorService() {
		return iConcentratorService;
	}

	/**
	 * @param iConcentratorService the iConcentratorService to set
	 */
	public void setiConcentratorService(IConcentratorService iConcentratorService) {
		this.iConcentratorService = iConcentratorService;
	}

	/**
	 * @return the iHeatMeterService
	 */
	@JSON(serialize=false)
	public IHeatMeterService getiHeatMeterService() {
		return iHeatMeterService;
	}

	/**
	 * @param iHeatMeterService the iHeatMeterService to set
	 */
	public void setiHeatMeterService(IHeatMeterService iHeatMeterService) {
		this.iHeatMeterService = iHeatMeterService;
	}

	/**
	 * @return the iProjectService
	 */
	@JSON(serialize=false)
	public IProjectService getiProjectService() {
		return iProjectService;
	}

	/**
	 * @param iProjectService the iProjectService to set
	 */
	public void setiProjectService(IProjectService iProjectService) {
		this.iProjectService = iProjectService;
	}

	/**
	 * @return the iQueryerService
	 */
	@JSON(serialize=false)
	public IQueryerService getiQueryerService() {
		return iQueryerService;
	}

	/**
	 * @param iQueryerService the iQueryerService to set
	 */
	public void setiQueryerService(IQueryerService iQueryerService) {
		this.iQueryerService = iQueryerService;
	}

	/**
	 * @return the iAssignMeterService
	 */
	@JSON(serialize=false)
	public IAssignMeterService getiAssignMeterService() {
		return iAssignMeterService;
	}

	/**
	 * @param iAssignMeterService the iAssignMeterService to set
	 */
	public void setiAssignMeterService(IAssignMeterService iAssignMeterService) {
		this.iAssignMeterService = iAssignMeterService;
	}

	/**
	 * @return the iHeatMeterTypeParamDictService
	 */
	@JSON(serialize=false)
	public IHeatMeterTypeParamDictService getiHeatMeterTypeParamDictService() {
		return iHeatMeterTypeParamDictService;
	}

	/**
	 * @param iHeatMeterTypeParamDictService the iHeatMeterTypeParamDictService to set
	 */
	public void setiHeatMeterTypeParamDictService(
			IHeatMeterTypeParamDictService iHeatMeterTypeParamDictService) {
		this.iHeatMeterTypeParamDictService = iHeatMeterTypeParamDictService;
	}

	/**
	 * @return the iSinkBiz
	 */
	@JSON(serialize=false)
	public ISinkBiz getiSinkBiz() {
		return iSinkBiz;
	}

	/**
	 * @param iSinkBiz the iSinkBiz to set
	 */
	public void setiSinkBiz(ISinkBiz iSinkBiz) {
		this.iSinkBiz = iSinkBiz;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the param
	 */
	public String getParam() {
		return param;
	}

	/**
	 * @param param the param to set
	 */
	public void setParam(String param) {
		this.param = param;
	}

	/**
	 * @return the entityUuid
	 */
	public String getEntityUuid() {
		return entityUuid;
	}

	/**
	 * @param entityUuid the entityUuid to set
	 */
	public void setEntityUuid(String entityUuid) {
		this.entityUuid = entityUuid;
	}

	/**
	 * @return the buildingUID
	 */
	public String getBuildingUID() {
		return buildingUID;
	}

	/**
	 * @param buildingUID the buildingUID to set
	 */
	public void setBuildingUID(String buildingUID) {
		this.buildingUID = buildingUID;
	}
	
}
